<template>
  <div>
    <div class="baseform">
      <el-form :label-position="labelPosition" label-width="80px" :model="from">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="案件种类" prop="caseTypeId">
              <el-select v-model="from.caseTypeId" placeholder style="width: 100%">
                <el-option
                  v-for="item in casetypelist"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="案件登记系统" prop="registerPlatform">
              <el-select v-model="from.registerPlatform" placeholder style="width: 100%">
                <el-option
                  v-for="item in casestyemlist"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="立案时间" prop="createTime">
              <!-- <el-input v-model="from.casetime"></el-input> -->
              <el-date-picker
                v-model="from.createTime"
                type="date"
                placeholder="选择日期"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="案发地点" prop="causeAddress">
              <el-input v-model="from.causeAddress" placeholder="案发地址" suffix-icon="fa fa-map-marker"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <div @click="showDetail(typeList.t1)">
              <el-form-item label="违法行为代码" prop="illegalTypeCode">
                <el-input v-model="from.illegalTypeCode" placeholder="违法行为代码必须输入">
                  <el-button slot="append" icon="el-icon-search"></el-button>
                </el-input>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div @click="showDetail(typeList.t2)">
              <el-form-item label="违法法规编码" prop="illegalLawNum">
                <el-input
                  v-model="from.illegalLawNum"
                  placeholder="违法法规编码"
                >
                  <el-button slot="append" icon="el-icon-search"></el-button>
                </el-input>
              </el-form-item>
            </div>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
              <el-form-item label="自由裁量权" prop="discretionid">
                <el-select v-model="from.discretionid" placeholder      @change="discretionidchange" style="width: 100%">
                  <el-option
                          v-for="item in discretionList"
                          :key="item.caseDiscretionId"
                          :label="item.caseCauseName"
                          :value="item.caseDiscretionId"
                  />
                </el-select>
              </el-form-item>
          </el-col>
          <el-col :span="12">
              <el-form-item label="拟处罚金额" prop="punishAmount">
                <el-input v-model="from.punishAmount" placeholder="请输入金额" suffix-icon="fa fa-money"/>
              </el-form-item>
          </el-col>
          <el-col :span="12">

          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="案由" prop="caseFacts">
              <!-- <el-input v-model="from.illegallaw"></el-input> -->
              <el-input
                type="textarea"
                :autosize="{ minRows: 2, maxRows: 12}"
                placeholder="请输入内容"
                v-model="from.caseFacts"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="违法事实" prop="illegalFacts">
              <!-- <el-input v-model="from.illegallaw"></el-input> -->
              <el-input
                type="textarea"
                :autosize="{ minRows: 2, maxRows: 12}"
                placeholder="请输入内容"
                v-model="from.illegalFacts"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="违法条例" prop="illegalLaw">
              <el-input
                type="textarea"
                :autosize="{ minRows: 2, maxRows: 12}"
                placeholder="请输入内容"
                v-model="from.illegalLaw"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="违法处罚依据" prop="illegalPunishmentStandard">
              <el-input
                type="textarea"
                :autosize="{ minRows: 2, maxRows: 12}"
                placeholder="请输入内容"
                v-model="from.illegalPunishmentStandard"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <break-info ref="breaklawinfo" @submit="getbreakdata" />
      </el-form>
    </div>
  </div>
</template>
<script>
import moment from 'moment';
import dictCache from "@/assets/utils/cache-dict-util";
import utils from "@/assets/utils/zhzf-util";
import FormBtns from "@/views/comps/zhzf/form-btns";
import casecauseApi from "@/api/system/casecause";
import caseCauselawcontentApi from "@/api/system/caseCauselawcontent";
import discretionApi from "@/api/system/discretion";
import breakInfo from "./break-info";
import { mapActions } from "vuex";
export default {
  components: { FormBtns, breakInfo },
  props: ["casetypelist", "casestyemlist"],
  data() {
    return {
      labelPosition: "right",
      from: {},
      breakinfoVisible: false,
      currType:'',
      discretionList:'',
      typeList: { t1: "1", t2: "2" }
    };
  },

  mounted() {
    //   this.initPage();
  },
  methods: {
    ...mapActions("d2admin/page", ["close"]),
    initPage(detail, distData) {
      this.from = detail;
      this.getdiscretion();
      this.initformdata();
      if(!this.from.casetime){
        this.from.casetime = new Date();
      }
    },
    initformdata(){
      console.log(this.discretionList);
      this.from.discretionid = this.discretionList[0].caseDiscretionId;
    },
    async getdiscretion(){//获取自由裁量相关信息
      let res = await discretionApi.pageList({pageSize: 10000, total: 0, pageIndex: 1});
      this.discretionList = res.data.rows;
    },
    discretionidchange(){
    },
    /**
     * 彈框类型
     */
    showDetail(type) {
      this.currType = type;
      this.$refs.breaklawinfo.initPage(type, this.from);
    },
    async getbreakdata(data) {
      if(this.currType == this.typeList.t1){
          if (!data) {
          return;
          } else {
            this.from.illegalTypeCode= data.casecauseNumber;
            this.from.casecauseId = data.casecauseId;
            this.from.asecauseContent = data.content;
            await this.getdata();
            this.$forceUpdate();
          }
      }else if(this.currType == this.typeList.t2){
          if (!this.from.illegalTypeCode){
            utils.showTips("请选择一个违法行为代码");
            return;
          } else {
            this.from.casecauseId = data.casecauseId;
            // this.from.asecauseContent = data.content;
            // await this.getdata();
            this.generatorLawData();
            this.$forceUpdate();
          }
      }
    },
    async getdata() {
      //获取法律法规
      let res1 = await caseCauselawcontentApi.getlawcontent({
        causeId: this.from.casecauseId
      });
      let defaultVal = res1.data.rows && res1.data.rows[0];
      if (!defaultVal) {
        //测试数据
        defaultVal = {
          code: "12345678",
          strName : '造成公路路产污染，损坏',
          yjtl:'《路政管理规定》第三十一条》',
          cfbz:''
        };
      }
      this.from.illegalLawNum = defaultVal.code;
      this.from.illegalLaw = defaultVal.strName;//违法条例
      this.from.illegalPunishmentStandard = defaultVal.yjtl+defaultVal.cfbz;
      this.generatorLawData();
    },
    async generatorLawData(){
        this.from.caseFacts = '涉嫌'+this.from.asecauseContent+'案';//案由
        this.from.illegalFacts = '执法人员在检查发现，当事人涉嫌'+this.from.asecauseContent;//*违法事实:
    }
  }
};
</script>
<style lang="scss">
.baseform {
  padding: 0px 20%;
}
</style>
